﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers.world {
    import net.wooga.pets.loading.vos.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.models.world.*;

    public class OnPatientClickedCommand extends Command {

        public var event:InfoEvent;
        public var world:WorldModel;
        public var sunModel:SunModel;
        public var languageModel:LanguageModel;
        public var userModel:UserModel;
        public var tutorialModel:TutorialModel;
        private var _roomId:String;

        private static const MAX_LEVEL_FOR_WAITING_PETS_HINT:int = 4;
        private static const MAX_LEVEL_FOR_WAITING_ELDER_HINT:int = 20;

        override public function execute():void{
            var _local2:Object;
            var _local3:RequestEvent;
            var _local1:ITreatable = (this.world.getActor(this.event.id) as ITreatable);
            if (!_local1){
                return;
            };
            this.giveHintForWaitingPets(_local1);
            if (_local1.hasClickHandler){
                _local1.clickHandler();
            } else {
                if ((((_local1.state == WorldConstants.PATIENT)) && ((_local1.targetType == GameConstants.TYPE_WAITING_ROOM)))){
                    _local1.moveToNextTreatment();
                } else {
                    if (_local1.state == WorldConstants.CURED){
                        if (((!(_local1.poked)) && (!(this.tutorialModel.isInTutorialMode)))){
                            _local1.poked = true;
                            this._roomId = _local1.roomId;
                            _local2 = {id:_local1.id};
                            _local2[ProtocolConstants.ROOM_ID] = this._roomId;
                            _local3 = new RequestEvent(EventConstants.SEND_REQUEST, this.onPoked);
                            _local3.addRequest("poke_patient", _local2);
                            dispatch(_local3);
                        };
                    } else {
                        if (_local1.state == WorldConstants.BABY){
                            _local1.moveToNextTarget(GameConstants.TYPE_KINDERGARTEN);
                        };
                    };
                };
            };
        }
        private function onPoked(_arg1:ResultVO):void{
            var _local2:ITreatable;
            if (_arg1.success){
                _local2 = (this.world.getActor(this.event.id) as ITreatable);
                dispatch(new InfoEvent(EventConstants.SHOW_THANK_YOU_ANI, null, _local2));
                dispatch(new InfoEvent(EventConstants.CREATE_REWARD_ICONS, this._roomId, (_arg1.data.poke_patient as Array)));
            };
        }
        private function giveHintForWaitingPets(_arg1:ITreatable):void{
            var _local2:String = this.world.getRoomIdsOfType(GameConstants.TYPE_WAITING_ROOM)[0];
            var _local3:Boolean = (((_arg1.targetType == null)) || ((_arg1.targetType == GameConstants.TYPE_WAITING_ROOM)));
            var _local4:Boolean = (((_arg1.roomId == _local2)) && ((_arg1.nextRoomId == null)));
            if (((_local4) && (_local3))){
                if ((((_arg1.diseaseName == WorldConstants.DISEASE_OLD)) && ((this.userModel.level <= MAX_LEVEL_FOR_WAITING_ELDER_HINT)))){
                    this.sunModel.simpleMessage = this.languageModel.getTextByKey("sun_message_waiting_elder");
                } else {
                    if (this.userModel.level <= MAX_LEVEL_FOR_WAITING_PETS_HINT){
                        this.sunModel.simpleMessage = this.languageModel.getTextByKey("sun_message_waiting_pet");
                    };
                };
            };
        }

    }
}//package net.wooga.pets.controllers.world 
